<?php
namespace App\Api;
use PhalApi\Api;

/**
 * 腾讯视频接口
 * @author: dogstar <chanzonghuang@gmail.com> 2014-10-04
 */
class Vids extends Api {
    public function getRules() {
        return array(
            'vid' => array(
                'url' => array('name'=> 'url','require' => true, 'desc' => '腾讯链接')
            ),
        );
    }

    /**
     * 腾讯视频接口
     * @desc 默认接口服务，当未指定接口服务时执行此接口服务
     * @return string title 标题
     * @return string content 内容
     * @return string version 版本，格式：X.X.X
     * @return int time 当前时间戳
     * @exception 400 非法请求，参数传递错误
     */
    public function vid() {
        $url = $this->url;
//        为了大义,宝石提亲
//        $url = 'https://v.qq.com/x/page/n3280ldowdb.html';
        $url_vid = preg_replace('/.*\/(.*)\.html/','$1',$url);

        $url = "http://vv.video.qq.com/getinfo?vids=$url_vid&platform=101001&charge=0&otype=json";
        $curl = new \PhalApi\CUrl();

        // 第二个参数，表示超时时间，单位为毫秒
        $rs = $curl->get($url, 3000);

        $rs = str_replace("QZOutputJson=",'',$rs);
        $rs = str_replace("};",'}',$rs);
        $rs = json_decode($rs,true);

        $v = $rs['vl']['vi'][0];
        $vid_url = $v['ul']['ui'][0]['url'].$v['fn']."?vkey=".$v['fvkey'];
        return  $vid_url;
    }

}
